package com.hvgroup.modules.sanic.repository;

import com.hvgroup.modules.sanic.domain.po.QaSession;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.Collection;
import java.util.List;

public interface QaSessionRepository extends JpaRepository<QaSession, Long>, JpaSpecificationExecutor<QaSession> {

    void deleteAllByChatIdInAndUserId(Collection<Long> ids, Long userIds);

    @Query(value = "SELECT distinct app_id from conv_qa_session where user_id = ? order by update_time desc", nativeQuery = true)
    List<String> findAppIdByUserId(Long userId);

    List<QaSession> findAllByUserIdOrderByUpdateTimeDesc(Long userId);

}
